Import('RTT_ROOT')
Import('rtconfig')
from building import *

cwd  = GetCurrentDir()

# add the general drivers.
src = Split("""
board.c
drv_clock.c
""")

list = os.listdir(cwd)
CPPPATH = [cwd]
objs = []

# add flash driver code
if GetDepend('BSP_USING_FLASH'):
    src += ['w25qxx.c','bd_flash.c']

# add tf card driver code
if GetDepend('BSP_USING_TF_CARD'):
    src = src + ['drv_spi_tfcard.c']

# add lcd driver code
if GetDepend('BSP_USING_LCD'):
    src = src + ['drv_lcd.c']

# add serial driver code
if GetDepend('BSP_USING_UART'):
    src = src + ['bd_usart.c']

# add i2c driver code
if GetDepend('BSP_USING_I2C'):
    src = src + ['drv_i2c.c']

# add spi driver code
if GetDepend('BSP_USING_SPI1') or GetDepend('BSP_USING_SPI2') or GetDepend('BSP_USING_SPI3'):
    src = src + ['drv_spi.c']

# add sdio driver code
if GetDepend('BSP_USING_SDIO'):
    src = src + ['drv_sdio_adapter.c']

# add qspi driver code
if GetDepend('BSP_USING_QSPI'):
    src = src + ['bd_qspi.c']

# add enc28j60 driver code
if GetDepend('BSP_USING_ENC28J60'):
    src = src + ['drv_enc28j60.c']

# add wlan driver code
if GetDepend('BSP_USING_WIFI'):
    src = src + ['drv_wlan.c']

# add pm driver code
if GetDepend('BSP_USING_PM'):
    src = src + ['drv_pm.c', 'drv_pmtimer.c', 'drv_wakeup.c']

# add adc driver code
if GetDepend('BSP_USING_ADC1_CH13'):
    src = src + ['drv_adc.c']

# add hwtimer driver code
if GetDepend('BSP_USING_PWM3_CH3'):
    src = src + ['drv_pwm.c']

# add infrared driver code
if GetDepend('BSP_USING_TIM15') or GetDepend('BSP_USING_TIM16'):
    src = src + ['drv_hwtimer.c']

# add HID USB driver code
if GetDepend('BSP_USING_USBD'):
    src = src + ['drv_usbd.c']

# add audio sound driver code
if GetDepend('BSP_USING_AUDIO'):
    src += Glob('./audio/*.c')
    CPPPATH += [cwd + "/audio"] 

# add watchdog driver code
if GetDepend('BSP_USING_WDT'):
    src = src + ['drv_wdt.c']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)

for d in list:
    path = os.path.join(cwd, d)
    if os.path.isfile(os.path.join(path, 'SConscript')):
        objs = objs + SConscript(os.path.join(d, 'SConscript'))
objs = objs + group

Return('objs')
